package com.ishowcode.Service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

@Service
@Slf4j
public class MQSender {
    //装配RabbitMQTemplete
    @Resource
    private RabbitTemplate rabbitTemplate;
    //方法:发送消息
    public void send(Object msg){
        log.info("发送消息-->"+msg);
        rabbitTemplate.convertAndSend("queue",msg);
    }
    //发送消息到交换机
    public void sendExchange(Object msg){
        log.info("发送消息-->"+msg);
        rabbitTemplate.convertAndSend("exchange","",msg);
    }
    //发送消息到direct交换机，同时指出路由
    public void sendDirect1(Object msg){
        log.info("direct1发送消息-->"+msg);
        rabbitTemplate.convertAndSend("exchange_direct","routing1",msg);
    }
    public void sendDirect2(Object msg){
        log.info("direct2发送消息-->"+msg);
        rabbitTemplate.convertAndSend("exchange_direct","routing2",msg);
    }
}
